// import { Component } from 'react'
import Taro ,{useReachBottom }from '@tarojs/taro'
import { useState,useEffect } from 'react'
import { View} from '@tarojs/components'
import { AtTabs, AtTabsPane } from 'taro-ui'
import {SpecialRecruit,CompanyChoose,PositionChoose} from'../../components'
import './index.scss'

export default function Employment()  {
  const [current,setCurrent]=useState(0)
  const [specialNum,setSpecialNum]=useState(1)
  const [positionNum,setPositionNum]=useState(1)
  const [companyNum,setCompanyNum]=useState(1)
  const tabList = [{ title: '专场招聘' }, { title: '招聘信息' }, { title: '企业选择' }]
  
  useEffect(()=>{
    if(Taro.getStorageSync(`currentPage`)){
      setCurrent(Taro.getStorageSync(`currentPage`));
    }
    console.log(Taro.getStorageSync(`currentPage`));
    // Taro.removeStorageSync(`currentPage`);

  },[])

  const handleClick =(value)=> {
          setCurrent(value)
  }

//如果含有条件进行筛选的话，数字又没有重新计数，会不会出问题？
  useReachBottom(()=>{
    if(current===0){
      console.log('special reach bottom!');
      let snum=specialNum
      setSpecialNum(snum+1)
    }
   else if(current===1){
      console.log('position reach bottom!');
      let pnum=positionNum
      setPositionNum(pnum+1)
    }
   else if(current===2){
      console.log('company reach bottom!');
      let cnum=companyNum
      setCompanyNum(cnum+1)
    }

  })
    return (
      <View className='index'>
         <AtTabs current={current} tabList={tabList} onClick={handleClick}>
        <AtTabsPane current={current} index={0} >
          <SpecialRecruit pageNum={specialNum} />
        </AtTabsPane>

        <AtTabsPane current={current} index={1} > 
        <PositionChoose pageNum={positionNum} changePositionNum={()=>{setPositionNum(1)}} />
        </AtTabsPane>
        
        <AtTabsPane current={current} index={2} >
        <CompanyChoose pageNum={companyNum} changeCompanyNum={()=>{setCompanyNum(1)}} />
        </AtTabsPane>
      </AtTabs>
      </View>
    )

}
